let pointList = []; // 每隔一秒存储的当前坐标
let timer; // 定时获取当前坐标
 
Page({
  /* 页面数据 */
  data: {
      polyline: [],
      longitude: 0,
      latitude: 0
  },
  /* 生命周期-加载 */
  onLoad(options){
      let that = this;
      // 获取设备定位
      wx.getLocation({
          type: 'gcj02',
          success: function (res) {
            let {latitude, longitude} = res;
            that.setData({
                longitude,
                latitude
            });
          }
      });
  },
  //获取经纬度并连线
  drawLine(){
    let _this = this;
    wx.getLocation({
      type: 'gcj02',
      success(res){
        // 获取经纬度
        let {latitude, longitude} = res;
        pointList.push({latitude, longitude});
        console.log(pointList);
        // 绘线
        _this.setData({
          longitude,
          latitude,
          polyline: [{
            points: pointList,
            color: '#99FF00',
            width: 4,
            dottedLine: true
          }]
        });
      }
    });
  },
  // 开始跑步
  start(){
    // 定时连点绘线
    timer = setInterval(this.drawLine, 500);
  },
  // 结束跑步
  end(){
    clearInterval(timer);
  }
});

